
$().ready(function() {
    validateRule();
    $("#healthCountUnit").ajaxChosen({
        category : 'clean-cycle-type'
    });

});


$.validator.setDefaults({
    submitHandler : function() {
        update();
    }
});

function validateRule() {
    var icon = "<i class='fa fa-times-circle'></i> ";
    $("#signupForm").validate({
        rules : {
            shopId:{  required : true  },
            terminalName : { required : true  },
            terminalNum : { required : true  },
            terminalType : { required : true  },
            checkCount : { required : true  },
            checkCountUnit : { required : true  },
        },
        messages : {
            shopId : {
                required : icon + "请选择企业"
            },
            terminalName : {
                required : icon + "请输入设备名称"
            },
            terminalNum : {
                required : icon + "请输入设备编号"
            },
            terminalType : {
                required : icon + "请选择设备工段"
            },
            checkCount : {
                required : icon + "请输入周期次数"
            },
            checkCountUnit : {
                required : icon + "请选择周期单位"
            }
        }
    })
}
function update() {
    var url = ctx + "module/terminal/fitting/" + ($('#signupForm').find("#id").val() == '' ? "save" : "update");
    $.ajax({
        cache : true,
        type : "POST",
        url : url,
        data : $('#signupForm').serialize(),// 你的formid
        async : false,
        error : function(request) {
            parent.layer.alert("Connection error");
        },
        success : function(data) {
            if (data.code == 0) {
                parent.layer.msg("操作成功");
                parent.reLoad();
                var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
                parent.layer.close(index);

            } else {
                parent.layer.alert(data.msg)
            }
        }
    });

}
